//
//  UIAlertController+Extension.swift
//  HinsLive
//
//  Created by haoxian on 2019/5/3.
//  Copyright © 2019 Hins. All rights reserved.
//

import UIKit

extension UIAlertController {
    static func alert(title: String? = nil, message: String? = nil) -> UIAlertController {
        return UIAlertController(title: nil, message: message, preferredStyle: .alert)
    }
    
    @discardableResult
    func addCancel(title: String = "取消", handler: ((UIAlertAction) -> Void)? = nil) -> UIAlertController {
        addAction(UIAlertAction(title: title, style: .cancel, handler: handler))
        return self
    }
    
    @discardableResult
    func addAction(title: String = "确定", handler: @escaping (UIAlertAction) -> Void) -> UIAlertController {
        addAction(UIAlertAction(title: title, style: .default, handler: handler))
        return self
    }
    
    func present() {
        let top = UIViewController.topViewController()
        top.present(self, animated: true)
    }
}
